package com.easyfun.healthmagicbox.bluetooth.meng;

import com.easyfun.healthmagicbox.bluetooth.BTMessageHandler;
import com.easyfun.healthmagicbox.bluetooth.BluetoothChatService;
import com.easyfun.healthmagicbox.bluetooth.MessageParser;
import com.easyfun.healthmagicbox.inputviews.HardwareInputActivity;
import com.easyfun.healthmagicbox.ormlite.HealthInputTypeEnum;
import com.easyfun.healthmagicbox.pojo.HealthInputData;
import com.easyfun.healthmagicbox.util.HealthDateUtil;

import android.content.Context;
import android.os.Message;


//The Handler that gets information back from the BluetoothChatService
public class MengHandler extends BTMessageHandler {

	
	private static final String TAG = MengHandler.class.getSimpleName();
	MengMessageParser parser = new MengMessageParser();
	public MengHandler(String personID, Context context, HardwareInputActivity parent)
	{
		super(personID, context,parent);
	}


	@Override
	protected void OnMessageWrite(byte[] msg, int len) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void OnMessageRead(byte[] readBuf, int len) {
		
		String readMessage = new String(readBuf, 0, len); 
		
		HealthInputData hid = new HealthInputData();
		
		MengMessage mm = parser.parse(readBuf, len);
		
		long dt = HealthDateUtil.getDate(
				HealthDateUtil.getCurrentDateStr(null), "yyyy-MM-dd HH:mm")
				.getTime();

		if (readMessage.contains("_W")) {
			hid.setValueTime(dt);
			hid.setPersonID(m_personid);
			hid.setValueData("75");
			hid.setValueType(HealthInputTypeEnum.TIZHONG.toInteger());
		}
		sound(hid);
		
	}

}
